// 文本 xml - 输出示例
package main

import (
	"encoding/xml"
	"fmt"
	"os"
)

type server struct {
	ServerName 	string `xml:"serverName"`
	ServerIP 	string	`xml:"serverIP"`
}

type Servers struct {
	XMLName	xml.Name 	`xml:"servers"`
	Version string 		`xml:"version, attr"`
	Svs 	[]server 	`xml:"server"`
}

func main() {
	v := &Servers{Version: "1"}
	v.Svs = append(v.Svs, server{"Shanghai_VPN", "127.0.0.1"})
	v.Svs = append(v.Svs, server{"Beijing_VPN", "127.0.0.1"})

	output, err := xml.MarshalIndent(v, " ", "  ")
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}
	os.Stdout.Write([]byte(xml.Header))

	os.Stdout.Write(output)
}

/*
输出内容：
<?xml version="1.0" encoding="UTF-8"?>
<servers version="1">
<server>
    <serverName>Shanghai_VPN</serverName>
    <serverIP>127.0.0.1</serverIP>
</server>
<server>
    <serverName>Beijing_VPN</serverName>
    <serverIP>127.0.0.2</serverIP>
</server>
</servers>
*/